package com.hunan.api.catv.mq.consumer;

import cn.hutool.json.JSONUtil;
import com.hunan.api.catv.entity.dto.OpenEventSwitchDto;
import com.hunan.api.catv.mq.MqConstants;
import com.hunan.api.catv.service.biz.member.sign.MemberSigninRecordBiz;
import com.hunan.api.catv.service.biz.system.SystemDictBiz;
import com.hunan.api.catv.utils.RedisUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author jiang zhuan
 * @version 1.0
 * @description 描述
 * @date 2021/2/1 0001
 * @package com.hunan.api.catv.mq.consumer
 * @company 湖南有线
 */
@Component
public class OpenAppEventConsumer {

    private static final String OPEN_EVENT_SWITCH_CONFIG = "open_event_switch_config";
    public static final Logger log = LoggerFactory.getLogger(MemberTryWatchLiveConsumer.class);
    @Autowired
    RedisUtils redisUtils;

    @Autowired
    SystemDictBiz systemDictBiz;
    @Autowired
    MemberSigninRecordBiz memberSigninRecordBiz;

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = MqConstants.OPEN_APP_EVENT_QUEUE, durable = "true"), exchange = @Exchange(value = MqConstants.OPEN_APP_EVENT_EXCHANGE, durable = "true", type = "topic"), key = MqConstants.OPEN_APP_EVENT_ROUTINGKEY))
    public void task(Integer memberId) {
        log.info("获取打开app事件,用户MemberId为:" + memberId);
        if (memberId == null) {
            return;
        }
        OpenEventSwitchDto openEventSwitch = null;
        try {
            openEventSwitch = JSONUtil.toBean(systemDictBiz.getStringByKey(OPEN_EVENT_SWITCH_CONFIG), OpenEventSwitchDto.class);
        } catch (Exception e) {
            log.error("获取开关配置错误", e);
            openEventSwitch = new OpenEventSwitchDto();
        }
        log.info("白金岛开光配置为：" + openEventSwitch.isPlatinumIslandSwitch());
        if (openEventSwitch.isPlatinumIslandSwitch()) {
            memberSigninRecordBiz.changePlatinumIslandInviteState(memberId);
        }


    }

}
